﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_DeliverAreaManager : ASPXBaseClass
{
    GZ.Entity.EDeliveryArea objDeliveryArea = new GZ.Entity.EDeliveryArea();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"].ToString() != "admin")
        {
            Response.Redirect("~/Admin/RedirectLogin.htm");
        }
        if (!IsPostBack)
        {
            BindDrp();
            BindRpt();
        }
    }

    void BindDrp()
    {
        GZ.Common.DataBindHelper.BindDropDownList("DeliveryAreaName", "Id", objDeliveryArea.GetDeliveryArea(0), this.drpRegion);
        GZ.Common.DataBindHelper.BindDropDownList("DeliveryAreaName", "Id", objDeliveryArea.GetDeliveryArea(Convert.ToInt32(this.drpRegion.SelectedValue)), this.drpBusinessDistrictId);
        GZ.Common.DataBindHelper.BindDropDownList("DeliveryAreaName", "Id", objDeliveryArea.GetDeliveryArea(Convert.ToInt32(this.drpBusinessDistrictId.SelectedValue)), this.drpOfficeId);
    }

    void BindRpt()
    {
        GZ.Common.DataBindHelper.BindRepeater(objDeliveryArea.GetDeliveryArea(Convert.ToInt32(this.drpOfficeId.SelectedValue)), this.rptDeliveryArea);
    }

    /// <summary>
    /// 查询方法
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        BindRpt();
    }

    /// <summary>
    /// Repeater命令事件
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptDeliveryArea_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int Id = Convert.ToInt32(e.CommandArgument);
        if (e.CommandName == "Del")
        {
            if (objDeliveryArea.Del(Id))
            {
                BindRpt();
            }
        }
        if (e.CommandName == "Edit")
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "edit", "<script>window.open ('AddDeliveryArea.aspx?Id=" + Id + "', 'edit', 'height=500,width=400,top=300,left=400,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no')</script>");
        }

    }

    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Server.Transfer("AddDeliveryArea.aspx");
    }
}